package com.aoxin.controller.course.systemCourse;

import java.util.LinkedList;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aoxin.service.inter.course.systemCourse.SchoolCourseToPageService;
import com.aoxin.util.AjaxRes;

@RestController
@RequestMapping("/web/system/")
public class SchoolCourseToPageController {
    @Autowired
    private SchoolCourseToPageService SchoolCourseToPageService;

    /**
     * 新增学校课程包对应课程
     *
     * @param res
     * @param
     * @return
     */
    @PostMapping("insertSchoolCourseToPage")
    public AjaxRes insertSchoolCourseToPage(AjaxRes res, Integer schoolCourseIds[], Integer schoolCoursePageId) {
        try {
            Integer col = SchoolCourseToPageService.insertSchoolCourseToPage(schoolCourseIds, schoolCoursePageId);
            res.setSucceed(col);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 查询学校课程包对应课程
     *
     * @param schoolCoursePageId
     * @return
     */
    @GetMapping("getSchoolCourseToPage")
    public AjaxRes getSchoolCourseToPage(AjaxRes res, Integer schoolCoursePageId) {
        try {
            LinkedList<Map<String, Object>> list = SchoolCourseToPageService.getSchoolCourseToPage(schoolCoursePageId);
            res.setSucceed(list);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 修改学校课程包对应课程
     *
     * @param schoolCourseToPageId
     * @return
     */
    @PutMapping("updateSchoolCourseToPage")
    public AjaxRes updateSchoolCourseToPage(AjaxRes res, Integer schoolCourseToPageId, Integer schoolCourseId) {
        try {
            Integer col = SchoolCourseToPageService.updateSchoolCourseToPage(schoolCourseToPageId, schoolCourseId);
            res.setSucceed(col);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 删除学校课程包对应课程
     *
     * @param schoolCourseToPageId
     * @return
     */
    @DeleteMapping("deleteSchoolCourseToPage")
    public AjaxRes deleteSchoolCourseToPage(AjaxRes res, Integer schoolCourseToPageId) {
        try {
            res.setSucceed(SchoolCourseToPageService.deleteSchoolCourseToPage(schoolCourseToPageId));
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }



}
